//
//  SDHSportsInteVC.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/3.
//

#import "SDHSportsInteVC.h"
#import "SDHSportsNetRequest.h"
#import "SDHSportsRequest.h"
#import "SDHSportsInteModel.h"
#import "MJExtension.h"

@interface SDHSportsInteVC () {
    
}

@property (nonatomic, strong) NSArray *subTabArray;
@property (nonatomic, strong) NSDictionary *configInfo;

@end

@implementation SDHSportsInteVC

- (id)init {
    if (self = [super init]) {
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    
    [self loadData];
}

- (void)endRefreshing {
    [MBProgressHUD hideHUD];
    [self reloadView];
}

- (void)loadData {
    
    SDHSportsRequest *request = [[SDHSportsRequest alloc] init];
    request.requestUrl = @"http://jsuywu8.com/guojitiyu/Tiyusaishi/getIntelligenceType";
    
    [MBProgressHUD showLoading];
    __weak typeof(self) weakSelf = self;
    [[SDHSportsNetRequest sharedRequest] sendRequest:request returnValueBlock:^(id  _Nonnull obj) {
        NSArray *array = obj[@"data"];
        _subTabArray = [SDHSportsInteModel mj_objectArrayWithKeyValuesArray:array];
        
        [weakSelf endRefreshing];
    } errorBlock:^(id  _Nonnull obj) {
        [weakSelf endRefreshing];
    } failureBlock:^{
        [weakSelf endRefreshing];
    }];
}

- (void)reloadView {
    
    if (_subTabArray.count <= 0) {
        return;
    }
    
    NSDictionary *item = nil;
    NSMutableArray *itemsArray = @[].mutableCopy;
    for (SDHSportsInteModel *model in _subTabArray) {
        NSString *title = model.league_en_name;
        if (title.length > 10) {
            title = [title substringToIndex:9];
        }
        item = @{
            @"itemType":@0,
            @"title":title,
            @"normalTitleColor":@"#FFFFFF",
            @"selectTitleColor":@"#FFFFFF",
            @"vcName":@"SDHSportsInteListVC",
            @"info":model
            };
        [itemsArray addObject:item];
    }
    
    _configInfo = @{
        @"topViewBgColor":@"#282B31",
        @"maskColor":@"#269FE7",
        @"type":@1,
        @"items":itemsArray
    };
    
    [self renderUI];
    [self tabItemSelected:0 needAnimation:NO];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
}

- (NSDictionary *)getPageConfigInfo {
    
    return _configInfo;
}


@end
